package com.shanshan.system.controller;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.shanshan.system.entity.Branch;
import com.shanshan.system.service.IBranchService;
import com.shanshan.system.vo.Result;
import com.shanshan.system.vo.SearchAdmin;
import com.shanshan.system.vo.SearchBranch;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shanshan
 * @since 2023-01-31
 */
@RestController
@RequestMapping("/system/branch")
@Api(tags = "菜单")
public class BranchController {
    @Autowired
    private IBranchService branchService;


    /**
     * @param id:
     * @return Result
     * @description 根据支部id查出部门信息
     */
    @GetMapping("/listId")
    public Result listId(Integer id){
        return branchService.listId(id);
    }

    /**
     * @param :
     * @return Result
     * @description 支部的查询
     */
    @GetMapping("/list")
    public Result list(){
        return branchService.selectAll();
    }

    /**
     * @param currentPage:
     * @param pageSize:
     * @param searchBranch:
     * @return Result
     * @description 条件的分页查询
     */
    @PostMapping("/selectAllBranch")
    public Result selectAllBranch(@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "5") int pageSize, @RequestBody SearchBranch searchBranch){
        return branchService.selectAllBranch(currentPage,pageSize,searchBranch);
    }

    /**
     * @param branch:
     * @return Result
     * @description 通过id删除部门
     */
    @PostMapping("/deleteBranch")
    public Result deleteBranch(@RequestBody Branch branch){
        return branchService.deleteBranch(branch);
    }

    /**
     * @param branch:
     * @return Result
     * @description 通过id进行修改
     */
    @PostMapping("/updateBranch")
    public Result updateBranch(@RequestBody Branch branch){
        return branchService.updateBranch(branch);
    }

    @PostMapping("/addBranch")
    public Result addBranch(@RequestBody Branch branch){
        return branchService.addBranch(branch);
    }
}
